<?php
  /**
   * PagesControl
   *
   * The PagesControl class provides page menegment
   *
   * @copyright Copyright (c) 2011, iJBlocks Progect
   */
    class PagesControl extends iJBlock
    {
        /**
         *
         * This function is construct Languages
         *
         *
         * @access public
         */
        public function __construct() {
        }
        
        /**
         * execute
         *
         * Executes the block to generate the tokens
         *
         * @return array Array with the tokens of the block
         *
         * @access public
         */
        public function execute() {
          $iJLanguages  = iJFactory::singleton('iJLanguages');
          $iJPages      = iJFactory::singleton('iJPages');
          if(isset($_GET['del']) && !empty($_GET['del'])) {
            $iJPages->delPageById($_GET['del']);
          }
          $page   = isset($_REQUEST['page'])                                  ? $_REQUEST['page'] : 1;
          $search = isset($_REQUEST['search']) && !empty($_REQUEST['search']) ? $_REQUEST['search'] : '';
          
          $pagesList = $iJPages->getPagesList($page, $search);
          
          $pages        = $pagesList[0];
          $QResultClass = $pagesList[1];
          
          
          
          $this->addToken('page',   $page);
          $this->addToken('pages',  $pages);
          $this->addToken('search', $search);
          $this->addToken('groups',     iJHrefLink::Icon('group')); 
          $this->addToken('pages_icon', iJHrefLink::Icon('web_page2')); 
          $this->addToken('delete_icon', iJHrefLink::Icon('trash'));
          $this->addToken('insert', iJHrefLink::linkToLocalPage('admin_pages_new'));
          
          $this->addToken('form_action', iJHrefLink::linkToLocalPage('admin_pages'));
          $this->addToken('curLanguage', $iJLanguages->getLanguage());
          $this->addToken('languages',   $iJLanguages->getLanguagesExeptCurrent());  
          
          $this->addToken('total_items',    $QResultClass->getSize());
          $this->addToken('pages_count',    $QResultClass->getPagesCount());
          $this->addToken('prev_link',      $QResultClass->getPerviousLink($page, 'admin_pages'));
          $this->addToken('next_link',      $QResultClass->getNextLink($page,     'admin_pages'));
          
          
          
          
          return parent::execute();
        }
        
        
        
         
        
    }
?>